package com.ailk.kbi.kbirazor.component
{
	
	import com.ailk.kbi.kbirazor.component.LinkLine;
	import com.ailk.kbi.kbirazor.component.NodeGroup;
	
	import flash.events.Event;
	
	import mx.collections.ArrayCollection;
	import mx.controls.Alert;
	import mx.core.IVisualElement;
	
	import spark.components.Group;
	import spark.components.HGroup;
	import spark.components.VGroup;
	
	
	public class ChildrenGroup extends HGroup{
		private var _contentXML:XML;
		
		
		private var _childrenNodeGroup:ChildrenNodeGroup;
		private var _linkLineGroup:LinkLineGroup;
		
		
		public function ChildrenGroup(contentXML:XML){
			super();

			_contentXML = contentXML;
			updateChildren();
		}
		
		private function updateChildren():void{
			this.gap = 0;
			_linkLineGroup = new LinkLineGroup(_contentXML);
			this.addElement(_linkLineGroup);
			
			_childrenNodeGroup = new ChildrenNodeGroup(_contentXML);	
			this.addElement(_childrenNodeGroup);
			
			_linkLineGroup.nodeGroupList = _childrenNodeGroup.nodeGroupList;
			
			_childrenNodeGroup.addEventListener("widthChanged", widthChangedHandler);
			_childrenNodeGroup.addEventListener("heightChanged", heightChangedHandler);
		}
		
		private function widthChangedHandler(event:Event):void {
			var newWidth:Number = (this.numElements - 1) * this.gap;
			for(var index:int = 0; index < this.numElements; index++){
				var element:IVisualElement = this.getElementAt(index);
				newWidth = newWidth + element.width;
			}
			this.width = newWidth;
		}
		
		private function heightChangedHandler(event:Event):void {
			this.height = _childrenNodeGroup.height;
			_linkLineGroup.height = this.height;
//			_linkLineGroup.ancherY = _childrenNodeGroup.ancherY;
		}
	}
}